1 Setup

print(paste0('../../../', '../motif_analysis/output/first_try/report/summary_table.txt'))
## [1] "../../../../motif_analysis/output/first_try/report/summary_table.txt"
if('../motif_analysis/output/first_try/report/summary_table.txt' != '') {
  highlight.snp.df <- read.table(paste0('../../../', '../motif_analysis/output/first_try/report/summary_table.txt'), header = T)
} else {
  highlight.snp.df <- NULL
}
rds.dirs <- strsplit('output/heart_motif_snp/Heart_Atrial_Appendage/fine-map__susie/,output/heart_motif_snp/Heart_Left_Ventricle/fine-map__susie/,output/heart_motif_snp/Muscle_Skeletal/fine-map__susie/', ',')[[1]]
output <- list()
for(rds.dir in rds.dirs) {
  tissue <- basename(dirname(rds.dir))
  cat('#', tissue, '
', '
')
  rdss <- Sys.glob(paste0('../../../', rds.dir, '/', '*.rds'))
  for(rds in rdss) {
    gene <- sub('.rds', '', basename(rds), fixed = T)
    cat('##', gene, '\n', '\n')
    out <- readRDS(rds)
    cs <- susieR::susie_get_CS(out$fitted, t(data.matrix(out$X[, -ncol(out$X)])), coverage = .95)

    # output[[length(output) + 1]] <- paste0(capture.output(pander(cs$purity)), collapse = '\n')
    pander(cs$purity)

    pip <- susieR::susie_get_PIP(out$fitted, cs$cs_index)
    coordinate <- as.numeric(str_match(out$X$SNP_ID, '[0-9]+_([0-9]+)_[A-Za-z]+_[A-Za-z]+_[A-Za-z0-9]+')[, 2])
    df <- data.frame(coordinate = coordinate, pip = pip)
    df$cs <- -1
    if(length(cs$cs_index) != 0) {
      for(i in 1 : length(cs$cs_index)) {
        df$cs[cs$cs[[i]]] <- cs$cs_index[i]
      }
    }
    p <- ggplot(df) + geom_point(aes(x = coordinate, y = pip, color = factor(cs)))
    p <- p + ggtitle('PIP (red line: leadingSNP; blue line: candidateSNP)')
    if(!is.null(highlight.snp.df)) {
      highlight.snp <- highlight.snp.df[highlight.snp.df$ensembl_gene_id == str_match(gene, '([A-Za-z0-9]+).[A-Za-z0-9]+')[, 2] & highlight.snp.df$tissue == tissue, ]
      leading.snp <- as.numeric(str_match(highlight.snp$leading_eqtl[1], '[0-9]+_([0-9]+)_[A-Za-z]+_[A-Za-z]+_[A-Za-z0-9]+')[, 2])
      candidate.snp <- unique(as.numeric(str_match(highlight.snp$motif_snp, '[0-9]+_([0-9]+)_[A-Za-z]+_[A-Za-z]+_[A-Za-z0-9]+')[, 2]))
      p <- p + geom_vline(xintercept = candidate.snp, color = 'blue')
    }
    p <- p + geom_vline(xintercept = leading.snp, color = 'red')
    x <- as.widget(ggplotly(p))
    output[[length(output) + 1]] <- x
    cat(renderTags(x)$html)
    cat('\n', '\n')
  }
}

2 Heart_Atrial_Appendage

2.1 ENSG00000103091.10

min.abs.corr mean.abs.corr median.abs.corr
0.9986 0.9993 0.9993
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

2.2 ENSG00000105738.6

min.abs.corr mean.abs.corr median.abs.corr
0.8491 0.9472 0.9414
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

2.3 ENSG00000114450.5

min.abs.corr mean.abs.corr median.abs.corr
0.999 0.9995 0.9997
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

2.4 ENSG00000139880.15

min.abs.corr mean.abs.corr median.abs.corr
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

2.5 ENSG00000141542.6

  min.abs.corr mean.abs.corr median.abs.corr
2 0.5863 0.804 0.7823
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

2.6 ENSG00000154229.7

min.abs.corr mean.abs.corr median.abs.corr
0.9647 0.9873 0.9866
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

2.7 ENSG00000177963.8

min.abs.corr mean.abs.corr median.abs.corr
0.956 0.9954 1
1 1 1
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

2.8 ENSG00000185615.11

min.abs.corr mean.abs.corr median.abs.corr
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

2.9 ENSG00000187860.6

min.abs.corr mean.abs.corr median.abs.corr
0.9589 0.992 0.9909
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

2.10 ENSG00000232112.3

min.abs.corr mean.abs.corr median.abs.corr
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3 Heart_Left_Ventricle

3.1 ENSG00000103091.10

min.abs.corr mean.abs.corr median.abs.corr
0.8432 0.942 0.9625
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3.2 ENSG00000105738.6

min.abs.corr mean.abs.corr median.abs.corr
0.9988 0.9995 1
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3.3 ENSG00000114450.5

min.abs.corr mean.abs.corr median.abs.corr
0.9912 0.9961 0.9981
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3.4 ENSG00000139880.15

min.abs.corr mean.abs.corr median.abs.corr
0.9137 0.9687 0.9789
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3.5 ENSG00000141542.6

min.abs.corr mean.abs.corr median.abs.corr
0.9932 0.9966 0.9966
0.5833 0.8071 0.8274
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3.6 ENSG00000154229.7

min.abs.corr mean.abs.corr median.abs.corr
0.9665 0.9876 0.9892
0.9883 0.9946 0.9946
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3.7 ENSG00000177963.8

min.abs.corr mean.abs.corr median.abs.corr
0.9815 0.9987 1
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3.8 ENSG00000185615.11

min.abs.corr mean.abs.corr median.abs.corr
1 1 1
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3.9 ENSG00000187860.6

min.abs.corr mean.abs.corr median.abs.corr
0.8145 0.9838 0.9896
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

3.10 ENSG00000232112.3

min.abs.corr mean.abs.corr median.abs.corr
0.899 0.979 0.9818
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

4 Muscle_Skeletal

4.1 ENSG00000105738.6

min.abs.corr mean.abs.corr median.abs.corr
0.9284 0.9652 0.9822
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

4.2 ENSG00000139880.15

min.abs.corr mean.abs.corr median.abs.corr
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

4.3 ENSG00000141542.6

min.abs.corr mean.abs.corr median.abs.corr
0.9924 0.9962 0.9962
1 1 1
0.6587 0.8294 0.8294
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

4.4 ENSG00000154229.7

min.abs.corr mean.abs.corr median.abs.corr
0.8583 0.9646 0.9685
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

4.5 ENSG00000177963.8

min.abs.corr mean.abs.corr median.abs.corr
0.6254 0.9133 0.9545
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

4.6 ENSG00000185615.11

min.abs.corr mean.abs.corr median.abs.corr
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

4.7 ENSG00000187860.6

min.abs.corr mean.abs.corr median.abs.corr
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`

4.8 ENSG00000232112.3

min.abs.corr mean.abs.corr median.abs.corr
0.9851 0.9966 1
0.9885 0.9956 0.9953
## Warning: 'as.widget' is deprecated.
## Use 'as_widget' instead.
## See help("Deprecated")
## We recommend that you use the dev version of ggplot2 with `ggplotly()`
## Install it with: `devtools::install_github('hadley/ggplot2')`